package ui.newgamescreen;

import java.awt.BorderLayout;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

import ui.ScreenPanel;
import ui.ScreenPanelManager;
import ui.TitlePanel;
import ui.mainscreen.MainScreenPanel;
import ui.newgamescreen.listeners.BackButtonListener;
import ui.newgamescreen.listeners.NextButtonListener;
import ui.newgamescreen.listeners.universeFormListener;
import ui.universescreen.UniverseScreenPanel;

public class NewGameScreenPanel extends ScreenPanel {

	private final TitlePanel titlePanel = new TitlePanel();
	private final ButtonPanel buttonPanel = new ButtonPanel();
	private final JPanel HorOptionPanel = new JPanel();
	private final JPanel VertOptionPanel = new JPanel();
	public final UniverseOptionPanel universeOptionPanel = new UniverseOptionPanel();
	public final PlayerOptionPanel playerOptionPanel = new PlayerOptionPanel();

	/* Реализация шаблона - Синглтон */
	private static NewGameScreenPanel instance;

	/**
	 * @return the instance
	 */
	public static synchronized NewGameScreenPanel getInstance() {
		if (instance == null) {
			instance = new NewGameScreenPanel();
		}
		return instance;
	}

	private NewGameScreenPanel() {

		setOnCreateProperties("image/bgd.jpg");

		add(buttonPanel, BorderLayout.SOUTH);
		add(titlePanel, BorderLayout.NORTH);

		/*
		 * Конструируем невидимые панели для расположения компонентов в центре
		 * экрана
		 */
		VertOptionPanel.setOpaque(false);
		VertOptionPanel.setVisible(true);
		VertOptionPanel.setLayout(new BoxLayout(VertOptionPanel, BoxLayout.Y_AXIS));
		VertOptionPanel.add(Box.createVerticalStrut(40));
		VertOptionPanel.add(HorOptionPanel);
		VertOptionPanel.add(Box.createVerticalStrut(40));

		HorOptionPanel.setOpaque(false);
		HorOptionPanel.setVisible(true);
		HorOptionPanel.setLayout(new BoxLayout(HorOptionPanel, BoxLayout.X_AXIS));
		HorOptionPanel.add(Box.createHorizontalStrut(40));
		HorOptionPanel.add(universeOptionPanel);
		HorOptionPanel.add(Box.createHorizontalStrut(40));
		HorOptionPanel.add(playerOptionPanel);
		HorOptionPanel.add(Box.createHorizontalStrut(40));

		/* Добавляем "невидимую" панель на экран */
		add(VertOptionPanel, BorderLayout.CENTER);
		
		/* Добавляем блок слушателей */
		addListeners();

	}

	@Override
	protected void addListeners() {
		buttonPanel.backButton.addActionListener(new BackButtonListener());
		universeOptionPanel.universeFormChooser.addActionListener(new universeFormListener(
			universeOptionPanel.clusterQuantityChooser));
		buttonPanel.nextButton.addActionListener(new NextButtonListener(this,buttonPanel.helpText));
	}

}
